package com.service.area;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.common.models.RetCode;
import com.common.models.RetResult;
import com.common.util.BlankUtil;
import com.dao.area.AreaMapper;

/**
 * 
* @ClassName: AreaServiceImpl
* @Description: 地区接口实现类
* @author hlq
* @date 2017年12月11日 下午3:26:43
*
 */
@Service("AreaService")
public class AreaServiceImpl implements AreaService{
	
	@Autowired
	private AreaMapper areaMapper;
	
	//根据城市Id获取区县列表
	@Override
	public RetResult getDistrictList(HashMap<String, Object> params) {
		RetResult ret = new RetResult();
		try {
			if(BlankUtil.isHttpNull((String)params.get("cityId"))){
				ret.setCode(RetCode.PARAM_ERR);
				ret.setMsg(RetCode.PARAM_ERR_MSG);
				return ret;
			}
			ret.setData(areaMapper.getDistrictList(params));
		} catch (Exception e) {
			e.printStackTrace();
			ret.setCode(RetCode.SERVER_ERR);
			ret.setMsg(RetCode.SERVER_ERR_MSG);
		}
		return ret;
	}
	
	//获取城市列表
	@Override
	public RetResult getCityList() {
		RetResult ret = new RetResult();
		try {
			
			ret.setData(areaMapper.getCityList());
		} catch (Exception e) {
			e.printStackTrace();
			ret.setCode(RetCode.SERVER_ERR);
			ret.setMsg(RetCode.SERVER_ERR_MSG);
		}
		return ret;
	}

	//获取热门城市列表
	@Override
	public RetResult getHotCityList() {
		RetResult ret = new RetResult();
		try {
			
			ret.setData(areaMapper.getHotCityList());
		} catch (Exception e) {
			e.printStackTrace();
			ret.setCode(RetCode.SERVER_ERR);
			ret.setMsg(RetCode.SERVER_ERR_MSG);
		}
		return ret;
	}
	
	//根据城市名称获取城市id
	@Override
	public RetResult getCityIdByCity(HashMap<String, Object> params){
		
		RetResult ret = new RetResult();
		try {
			
			
			String cityId = areaMapper.getCityIdByCity(params);
		
			ret.setData(cityId);
			
		} catch (Exception e) {
			e.printStackTrace();
			ret.setCode(RetCode.SERVER_ERR);
			ret.setMsg(RetCode.SERVER_ERR_MSG);
		}
		return ret;
	}
	
	

}
